import store from '@/store';
import {
	// mutations
	setDynamicList,
	setCommunityDetailData,
	setCommunityDetailCommentListData,
	setDetailCommentReplyData,
	updateCommunityDetailDataCommentList,
	updateCommunityDetailDataCommentListReply,
	upDateArticleDetailCommentListLike,
	setUserPersonListInformationData,
	setUserPersonDynamicDraftData,
	setArticleShareQrcode,
	setHomeAd,
	setHomeQuickEntry,
	UPDATE_LIST_VIEW_COMMENT_LIKE_ARTICLE,
	UPDATE_DELETE_ARTICLE,
	// actions
	GET_HOME_AD,
	GET_HOME_QUICK_ENTRY,
	LOAD_DYNAMIC_LIST,
	LOAD_COMMUNITY_DETAIL_DATA,
	LOAD_COMMUNITY_PREVIEW_DETAIL_DATA,
	LOAD_COMMUNITY_DETAIL_COMMENT_LIST,
	LOAD_DETAIL_COMMENT_REPLY_LIST,
	LOAD_MORE_DETAIL_COMMENT_REPLY_LIST,
	INSERT_ARTICLE_COMMENT,
	UPDATE_LIKE_ARTICLE,
	UPDATE_LIKE_COMMENT,
	UPDATE_LIKE_COMMENT_REPLY,
	REPORT_ARTICLE,
	DELETE_ARTICLE,
	GET_ARTICLE_SHARE_QRCODE,
	DELETE_ARTICLE_COMMENT,
	INSERT_ARTICLE_COMMENT_REPLY,
	DELETE_ARTICLE_COMMENT_REPLY,
	//
	GET_USER_PERSON_LIST_INFORMATION,
	INSERT_USER_PERSON_DYNAMIC,
	GET_USER_PERSON_DYNAMIC_DRAFT,
	ARTICLE_SHARE_ADD,
} from './actions';
import { UPDATE_USER_RELEASE_COUNT } from '../app/actions';

const prefixUrl = () => uni.$http.homePrefixUrl;
export default {
	state:{
		name: 'home',
		//
		homeAd: [],
		homeQuickEntry: [],
		//
		homeRecommendData: [],
		newHomeDynamicData: false,
    homeDynamicData: [],
		homeInformationData: [],
		//
		articleDetailCacheData: {},
		communityDetailData: {},
		communityDetailCommentListData: {},
		detailCommentReplyData: { commentReplyList: [] },
		articleShareQrcode: null,
		//
		userPersonInformationCacheData: {},
		userPersonListInformationData: {},
		userPersonDynamicDraftData: {},
	},
	getters: {
		test(state) {
			return state.test
		},
	},
	mutations: {
		[setDynamicList] (state, { data, params = {} }) {
			// console.log('setDynamicList 1', params, state.homeRecommendData);
			const { refresh, isRecommend, isDynamic, isInformation } = params
			let type;
			if (isDynamic || isInformation) {
				type = isDynamic ? 'UGC' : 'PGC';
			}
			const dataValue = data.map(item => ({ ...item, type: item.type || type, isRecommend, isDynamic, isInformation }));
			if (isRecommend) {
				if (refresh) {
					state.homeRecommendData = dataValue;
				} else {
					state.homeRecommendData = [...state.homeRecommendData, ...dataValue];
				}
			}
			if (isDynamic) {
				if (refresh) {
					if (state.homeDynamicData[0] && dataValue[0] && state.homeDynamicData[0].uniqueID !== dataValue[0].uniqueID) {
						state.newHomeDynamicData = true;
					} else {
						state.newHomeDynamicData = false;
					}
					state.homeDynamicData = dataValue;
				} else {
					state.homeDynamicData = [...state.homeDynamicData, ...dataValue];
				}
			}
			if (isInformation) {
				if (refresh) {
					state.homeInformationData = dataValue;
				} else {
					state.homeInformationData = [...state.homeInformationData, ...dataValue];
				}
			}
		},
		[setCommunityDetailData] (state, { data, params }) {
			const { communityDetailData, communityDetailCommentListData } = state;
			const { uniqueID } = params;
			const { commentList: detailCommentList = [] } = data;
			state.communityDetailData = {
				...communityDetailData,
				[uniqueID + '']: data || {},
			};
			state.communityDetailCommentListData = {
				...communityDetailCommentListData,
				[uniqueID + '']: detailCommentList,
			};
		},
		[setCommunityDetailCommentListData] (state, { data, params }) {
			const { communityDetailCommentListData } = state;
			const { uniqueID } = params;
			const existData = communityDetailCommentListData[uniqueID + ''] || [];
			state.communityDetailCommentListData = {
				...communityDetailCommentListData,
				[uniqueID + '']: [...existData, ...data]
			};
		},
		[setDetailCommentReplyData] (state, { data, params, isLoadMore }) {
			const { detailCommentReplyData } = state;
			const { uniqueID, commentID } = params;
			if (isLoadMore) {
				const existData = detailCommentReplyData[uniqueID + commentID + ''] || { commentReplyList: [] };
				state.detailCommentReplyData = {
					...detailCommentReplyData,
					[uniqueID + commentID + '']: {
						...existData,
						commentReplyList: [...existData.commentReplyList, ...data],
					},
				};
			} else {
				state.detailCommentReplyData = {
					...detailCommentReplyData,
					[uniqueID + commentID + '']: data,
				};
			}
		},
		// 文章评论后添加新增/删除评论到列表
		[updateCommunityDetailDataCommentList] (state, { data, params, commentID }) {
			const { communityDetailData, communityDetailCommentListData } = state;
			const { uniqueID, replyTotal = 0, likeTotal = 0 } = params;
			const existData = communityDetailCommentListData[uniqueID + ''] || [];
			if (commentID) { // 删除评论
				state.communityDetailCommentListData = {
					...communityDetailCommentListData,
					[uniqueID + '']: existData.filter(item => item.commentID !== commentID),
				};
			} else {
				state.communityDetailCommentListData = {
					...communityDetailCommentListData,
					[uniqueID + '']: [data, ...existData],
				};
			}
			//更新文章详情的评论总数, 点赞总数
			const deleteDiscussTotal = replyTotal + 1;
			const deleteLikeTotal = likeTotal;
			const existDetailData = communityDetailData[uniqueID + ''];
			if (existDetailData) {
				state.communityDetailData = {
					...communityDetailData,
					[uniqueID + '']: {
						...existDetailData,
						discussTotal: commentID ? existDetailData.discussTotal - deleteDiscussTotal : existDetailData.discussTotal + 1,
						likeTotal: commentID ? existDetailData.likeTotal - deleteLikeTotal : existDetailData.likeTotal,
					}
				};
			}
		},
		// 文章评论被回复后添加新增/删除回复到列表
		[updateCommunityDetailDataCommentListReply] (state, { data, params, commentID, replyID, isComFormAllReply }) {
			if (isComFormAllReply) { // 是否是在全部回复列表调用而来
				const { detailCommentReplyData } = state;
				const { uniqueID, commentID } = params;
				const existData = detailCommentReplyData[uniqueID + commentID + ''] || {};
				if (replyID) { // 删除回复评论
					state.detailCommentReplyData = {
						...detailCommentReplyData,
						[uniqueID + commentID + '']: {
							...existData,
							replyTotal: existData.replyTotal - 1,
							commentReplyList: existData.commentReplyList.filter(reply => reply.replyID !== replyID)
						}
					};
				} else { // 添加回复评论
					state.detailCommentReplyData = {
						...detailCommentReplyData,
						[uniqueID + commentID + '']: {
							...existData,
							replyTotal: existData.replyTotal + 1,
							commentReplyList: [data, ...existData.commentReplyList],
						},
					};
				}
			}
			const { communityDetailCommentListData } = state;
			const { uniqueID } = params;
			const existData = communityDetailCommentListData[uniqueID + ''] || [];
			// 在文章详情的评论列表
			if (replyID) { // 删除文章评论
				state.communityDetailCommentListData = {
					...communityDetailCommentListData,
					[uniqueID + '']: existData.map(item => {
						if (item.commentID === commentID) {
							let { commentReplyList = [] } = item;
							commentReplyList = commentReplyList.filter(reply => reply.replyID !== replyID);
							return {
								...item,
								replyTotal: item.replyTotal - 1,
								commentReplyList,
							};
						}
						return { ...item };
					}),
				};
			} else { // 添加回复评论
				state.communityDetailCommentListData = {
					...communityDetailCommentListData,
					[uniqueID + '']: existData.map(item => {
						if (item.commentID === data.commentID) {
							let { commentReplyList = [] } = item;
							commentReplyList = [data, ...commentReplyList];
							return {
								...item,
								replyTotal: item.replyTotal + 1,
								commentReplyList,
							};
						}
						return { ...item };
					})
				};
			}
			//更新文章详情的评论总数
			const { communityDetailData } = state;
			const existDetailData = communityDetailData[uniqueID + ''];
			if (existDetailData) {
				const { likeTotal = 0 } = params;
				const deleteLikeTotal = likeTotal;
				state.communityDetailData = {
					...communityDetailData,
					[uniqueID + '']: {
						...existDetailData,
						discussTotal: replyID ? existDetailData.discussTotal - 1 : existDetailData.discussTotal + 1,
						likeTotal: replyID ? existDetailData.likeTotal - deleteLikeTotal: existDetailData.likeTotal,
					}
				};
			}
		},
		// 文章点赞后修改列表的点赞、浏览、评论数量
		[UPDATE_LIST_VIEW_COMMENT_LIKE_ARTICLE] (state, params) {
			const { isLikeArticle, articleUserID, uniqueID, likeStatus, isRecommend, isDynamic, isInformation,
				isUpdateView, isUpdateComment, deleteComment, replyTotal = 0, likeTotal = 0 } = params;
			const deleteDiscussTotal = replyTotal + 1;
			const deleteLikeTotal = likeTotal;
			let stateKey;
			if (isRecommend) {
				stateKey = 'homeRecommendData';
			} else if (isDynamic) {
				stateKey = 'homeDynamicData';
			} else if (isInformation) {
				stateKey = 'homeInformationData';
			}
			// console.log('UPDATE_LIST_VIEW_COMMENT_LIKE_ARTICLE', params, stateKey, state[stateKey]);
			if (stateKey) {
				state[stateKey] = state[stateKey].map(item => {
					if (item.uniqueID + '' === uniqueID + '') {
						if (isUpdateView) { // 1为已读，0为未读
							// if (item.addView === '1') {
							// 	return { ...item };
							// }
							return {
								...item,
								addView: '1',
								pvtotal: item.pvtotal + 1,
							};
						}
						if (isUpdateComment) {
							return {
								...item,
								discussTotal: deleteComment ? item.discussTotal - deleteDiscussTotal : item.discussTotal + 1,
								likeTotal: deleteComment ? item.likeTotal - deleteLikeTotal : item.likeTotal,
							};
						}
						return {
							...item,
							likeStatus: isLikeArticle ? (likeStatus ? 1 : 0) : item.likeStatus,
							likeTotal: likeStatus ? item.likeTotal + 1 : item.likeTotal - 1,
						};
					}
					return { ...item };
				});
			} else { // 从个人中心进入详情，操作评论。点赞等的处理
				['homeRecommendData', 'homeDynamicData', 'homeInformationData'].forEach(key => {
					state[key] = state[key].map(item => {
						if (item.uniqueID + '' === uniqueID + '') {
							if (isUpdateView) { // 1为已读，0为未读
								// if (item.addView === '1') {
								// 	return { ...item };
								// }
								return {
									...item,
									addView: '1',
									pvtotal: item.pvtotal + 1,
								};
							}
							if (isUpdateComment) {
								return {
									...item,
									discussTotal: deleteComment ? item.discussTotal - deleteDiscussTotal : item.discussTotal + 1,
									likeTotal: deleteComment ? item.likeTotal - deleteLikeTotal : item.likeTotal,
								};
							}
							return {
								...item,
								likeStatus: isLikeArticle ? (likeStatus ? 1 : 0) : item.likeStatus,
								likeTotal: likeStatus ? item.likeTotal + 1 : item.likeTotal - 1,
							};
						}
						return { ...item };
					});
				});
			}
			if (!stateKey || stateKey === 'homeDynamicData') {
				//更新个人中心相关数据
				if (articleUserID) {
					const { userPersonListInformationData } = state;
					const existData = userPersonListInformationData[articleUserID + ''] || [];
					// console.log('existData', userPersonListInformationData, existData);
					state.userPersonListInformationData = {
						...userPersonListInformationData,
						[articleUserID + '']: {
							...existData,
							personalLikeTotal: (!isUpdateView && !isUpdateComment) ? (likeStatus ? existData.personalLikeTotal + 1 : existData.personalLikeTotal - 1) : existData.personalLikeTotal,
							trendsContextList: existData.trendsContextList ? existData.trendsContextList.map(item => {
								if (item.uniqueID + '' === uniqueID + '') {
									if (isUpdateView) { // 1为已读，0为未读
										// if (item.addView === '1') {
										// 	return { ...item };
										// }
										return {
											...item,
											addView: '1',
											pvtotal: item.pvtotal + 1,
										};
									}
									if (isUpdateComment) {
										return {
											...item,
											discussTotal: deleteComment ? item.discussTotal - deleteDiscussTotal : item.discussTotal + 1,
											likeTotal: deleteComment ? item.likeTotal - deleteLikeTotal : item.likeTotal,
										};
									}
									return {
										...item,
										likeStatus: isLikeArticle ? (likeStatus ? 1 : 0) : item.likeStatus,
										likeTotal: likeStatus ? item.likeTotal + 1 : item.likeTotal - 1,
									};
								}
								return { ...item };
							}) : [],
						},
					};
				}
			}
			//更新详情的文章点赞数
			if (!isUpdateView && !isUpdateComment) {
				const { communityDetailData } = state;
				const existData = communityDetailData[uniqueID + ''] || {};
				if (existData) {
					state.communityDetailData = {
						...communityDetailData,
						[uniqueID + '']: {
							...existData,
							likeStatus: isLikeArticle ? (likeStatus ? 1 : 0) : existData.likeStatus,
							likeTotal: likeStatus ? existData.likeTotal + 1 : existData.likeTotal - 1,
						},
					};
				}
			}
		},
		[UPDATE_DELETE_ARTICLE] (state, params) {
			const { articleUserID, uniqueID, isRecommend, isDynamic, isInformation, likeTotal } = params;
			let stateKey;
			if (isRecommend) {
				stateKey = 'homeRecommendData';
			}
			if (isDynamic) {
				stateKey = 'homeDynamicData';
			}
			if (isInformation) {
				stateKey = 'homeInformationData';
			}
			// console.log('UPDATE_DELETE_ARTICLE', params, stateKey, state[stateKey]);
			if (stateKey) {
				state[stateKey] = state[stateKey].filter(item => item.uniqueID + '' !== uniqueID + '');
			} else { // 从个人中心进入详情，操作的处理
				['homeRecommendData', 'homeDynamicData', 'homeInformationData'].forEach(key => {
					state[key] = state[key].filter(item => item.uniqueID + '' !== uniqueID + '');
				});
			}
			//更新个人中心相关数据
			if (articleUserID) {
				const { userPersonListInformationData } = state;
				const existData = userPersonListInformationData[articleUserID + ''] || {};
				// console.log('existData', userPersonListInformationData, existData);
				state.userPersonListInformationData = {
					...userPersonListInformationData,
					[articleUserID + '']: {
						...existData,
						personalReleaseTotal: existData.personalReleaseTotal && existData.personalReleaseTotal - 1,
						personalLikeTotal: existData.personalLikeTotal - likeTotal,
						trendsContextList: existData.trendsContextList ? existData.trendsContextList.filter(item => item.uniqueID + '' !== uniqueID + ''): [],
					},
				};
			}
		},
		// 在评论详情页点赞评论更新文章详情页的评论点赞数
		[upDateArticleDetailCommentListLike] (state, params) {
			const { communityDetailCommentListData } = state;
			const { uniqueID, commentID, likeStatus } = params;
			const existData = communityDetailCommentListData[uniqueID + ''] || [];
			// console.log('upDateArticleDetailCommentListLike1', params);
			state.communityDetailCommentListData = {
				...communityDetailCommentListData,
				[uniqueID + '']: existData.map(item => {
					if (commentID + '' === item.commentID + '') {
						return {
							...item,
							likeStatus: likeStatus ? 1 : 0,
							likeTotal: likeStatus ? item.likeTotal + 1 : item.likeTotal - 1,
						};
					}
					return { ...item };
				}),
			};
		},
		// 个人中心
		[setUserPersonListInformationData] (state, { params, data, isLoadMore }) {
			const { userPersonListInformationData } = state;
			const { userID } = params;
			if (isLoadMore) {
				let existData = userPersonListInformationData[userID + ''] || { trendsContextList: [] };
				existData = {
					...existData,
					trendsContextList: [...existData.trendsContextList, ...data],
				};
				state.userPersonListInformationData = {
					...userPersonListInformationData,
					[userID + '']: existData,
				};
			} else {
				state.userPersonListInformationData = {
					...userPersonListInformationData,
					[userID + '']: data || { trendsContextList: [] },
				};
			}
		},
		// 发布个人动态
		[INSERT_USER_PERSON_DYNAMIC] (state, { data }) {
			// context: "的发生都发生"
			// date: "2021-04-28 18:54:54"
			// pageNum: null
			// pageSize: null
			// pictures: []
			// status: "1"
			// uniqueID: "10046"
			// userID: "20007"
			const { ifHide = 'Y' } = state.homeDynamicData[0] || {};
			const { icon, nickname, id } = store.state.app.umsMember;
			const item = {
				...data,
				type: 'UGC',
				pvtotal: 0,
				discussTotal: 0,
				likeStatus: 0,
				likeTotal: 0,
				ifHide,
				//
				addView: "0",
				commentList: null,
				icon,
				userID: id,
				userName: nickname,
			};
			state.homeDynamicData = [item, ...state.homeDynamicData];
			// 如果是在个人中心进入发布动态，个人中心新增
			const { userPersonListInformationData } = state;
			const { userID } = item;
			let existData = userPersonListInformationData[userID + ''] || { trendsContextList: [] };
			existData = {
				...existData,
				personalReleaseTotal: existData.personalReleaseTotal ? existData.personalReleaseTotal + 1 : 1,
				trendsContextList: [item, ...existData.trendsContextList],
			};
			state.userPersonListInformationData = {
				...userPersonListInformationData,
				[userID + '']: existData,
			};
		},
		[setUserPersonDynamicDraftData] (state, { data }) {
			state.userPersonDynamicDraftData = data || {};
		},
		[setArticleShareQrcode] (state, { data }) {
			state.articleShareQrcode = data;
		},
		[setHomeAd] (state, { data }) {
			state.homeAd = data;
		},
		[setHomeQuickEntry] (state, { data }) {
			state.homeQuickEntry = data;
		},
	},
	actions: {
		// 社区首页广告数据
		async [GET_HOME_AD] ({ commit }, params) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/recommend/getAdsense', params);
				if (res) {
					const { data = [] } = res;
					commit(setHomeAd, { data })
				}
				return res;
			} catch (error) {
				console.error('GET_HOME_AD', error);
				return error;
			}
		},
		// 社区首页快捷入口数据
		async [GET_HOME_QUICK_ENTRY] ({ commit }, params) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/recommend/getQuicklyEntry', params);
				if (res) {
					const { data = [] } = res;
					commit(setHomeQuickEntry, { data })
				}
				return res;
			} catch (error) {
				console.error('GET_HOME_QUICK_ENTRY', error);
				return error;
			}
		},
		// 社区首页列表数据
		async [LOAD_DYNAMIC_LIST] ({ commit }, params) {
			let url = prefixUrl() + '/recommend/getRecommendList';
			const { isRecommend, isDynamic, isInformation, ...rest } = params
			if (isRecommend) {
				url = prefixUrl() + '/recommend/getRecommendList';
			}
			if (isDynamic) {
				url = prefixUrl() + '/dynamic/getDynamicList';
			}
			if (isInformation) {
				url = prefixUrl() + '/information/getInformationList';
			}
			try {
				const res = await uni.$http.post(url, rest);
				if (res) {
					const { data = [] } = res;
					commit(setDynamicList, { data, params })
				}
				return res;
			} catch (error) {
				console.error('LOAD_DYNAMIC_LIST', error);
				return error;
			}
		},
		// 社区首页进入详情数据
		async [LOAD_COMMUNITY_DETAIL_DATA] ({ commit }, params) {
			let url = prefixUrl() + '/dynamic/getDynamicContext';
			const { isDynamic, isInformation, ...rest } = params
			if (isDynamic) {
				url = prefixUrl() + '/dynamic/getDynamicContext';
			}
			if (isInformation) {
				url = prefixUrl() + '/information/getInformationContext';
			}
			try {
				const res = await uni.$http.post(url, rest);
				if (res) {
					const { data = {} } = res;
					commit(setCommunityDetailData, { data, params });
				}
				if (res && res.code === 200) {
					// 进入详情成功更新列表的阅读数量
					commit(UPDATE_LIST_VIEW_COMMENT_LIKE_ARTICLE, params);
				}
				return res;
			} catch (error) {
				commit(setCommunityDetailData, { data: {}, params });
				console.error('LOAD_COMMUNITY_DETAIL_DATA', error);
				return error;
			}
		},
		// 获取文章预览详情数据
		async [LOAD_COMMUNITY_PREVIEW_DETAIL_DATA] ({ commit }, params) {
			try {
				const { uniqueID } = params;
				const res = await uni.$http.post(prefixUrl() + '/information/getPreview/' + uniqueID);
				return res;
			} catch (error) {
				console.error('LOAD_COMMUNITY_PREVIEW_DETAIL_DATA', error);
				return error;
			}
		},
		// 社区首页进入详情获取评论数据
		async [LOAD_COMMUNITY_DETAIL_COMMENT_LIST] ({ commit }, params) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/comment/getCommentList', params);
				if (res) {
					const { data = [] } = res;
					commit(setCommunityDetailCommentListData, { params, data })
				}
				return res;
			} catch (error) {
				commit(setCommunityDetailCommentListData, { params, data: [] })
				console.error('LOAD_COMMUNITY_DETAIL_COMMENT_LIST', error);
				return error;
			}
		},
		// 进入评论详情获取回复列表数据
		async [LOAD_DETAIL_COMMENT_REPLY_LIST] ({ commit }, params) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/comment/getComment', params);
				if (res) {
					const { data = [] } = res;
					commit(setDetailCommentReplyData, { params, data: data[0] || { commentReplyList: [] } })
				}
				return res;
			} catch (error) {
				console.error('LOAD_DETAIL_COMMENT_REPLY_LIST', error);
				return error;
			}
		},
		// 进入评论详情获取回复列表数据
		async [LOAD_MORE_DETAIL_COMMENT_REPLY_LIST] ({ commit }, params) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/reply/getReplyList', params);
				if (res) {
					const { data = [] } = res;
					commit(setDetailCommentReplyData, { params, isLoadMore: true, data: data || [] })
				}
				return res;
			} catch (error) {
				console.error('LOAD_MORE_DETAIL_COMMENT_REPLY_LIST', error);
				return error;
			}
		},
		// 评论文章
		async [INSERT_ARTICLE_COMMENT] ({ commit }, params) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/comment/add', params);
				if (res && res.code === 200 && res.data) {
					const { commentID, code } = res.data;
					if (code === '500') {
						uni.showToast({
							title: '评论内容违规',
							duration: 2000,
							icon: 'none',
						});
					} else {
						const {
							// beReplyID,
							uniqueID,
							context,
							date,
						} = params;
						const { icon, nickname, id } = store.state.app.umsMember;
						const data = {
							icon, //评论者头像地址
							userName: nickname, //评论者用户名
							userID: id, //评论者用户ID
							commentID, //评论ID
							uniqueID, //文章ID
							date, //评论时间
							context, //评论内容
							likeTotal: 0, //评论点赞总数
							likeStatus: 0, //点赞状态，0：未点赞、1：点赞
						};
						commit(updateCommunityDetailDataCommentList, { params, data });
						// 评论文章成功更新列表的评论数量
						commit(UPDATE_LIST_VIEW_COMMENT_LIKE_ARTICLE, params);
						uni.showToast({
							title: res && res.code === 200 ? '发布成功' : '发布失败，请重试',
							duration: 2000,
							icon: 'none'
						});
					}
				}
				return res;
			} catch (error) {
				console.error('INSERT_ARTICLE_COMMENT', error);
				return error;
			}
		},
		// 删除文章评论
		async [DELETE_ARTICLE_COMMENT] ({ commit }, params) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/comment/del', params);
				if (res && res.code === 200) {
				}
				const {
					commentID,
				} = params;
				commit(updateCommunityDetailDataCommentList, { params, commentID });
				// 文章评论删除成功更新列表的评论数量
				commit(UPDATE_LIST_VIEW_COMMENT_LIKE_ARTICLE, params);
				return res;
			} catch (error) {
				console.error('DELETE_ARTICLE_COMMENT', error);
				return error;
			}
		},
		// 回复文章的评论
		async [INSERT_ARTICLE_COMMENT_REPLY] ({ commit }, params) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/reply/commentReply', params);
				if (res && res.code === 200 && res.data) {
					const { replytID: replyID, code } = res.data;
					if (code === '500') {
						uni.showToast({
							title: '评论内容违规',
							duration: 2000,
							icon: 'none',
						});
					} else {
						const {
							isComFormAllReply, // 是否是在全部回复列表调用而来
							articleUserID,
							//
							repliedUserName,
							beReplyID,
							uniqueID,
							commentID,
							context,
							date,
							type, //type,0:回复评论，1：回复-回复
						} = params;
						const { icon, nickname, id } = store.state.app.umsMember;
						const data = {
							icon,//回复者头像地址
							userName: nickname,//回复者用户名字
							userID: id,//回复者用户ID
							replyID,//回复ID
							commentID,//评论ID
							uniqueID,//文章ID
							date,//回复时间
							context,//回复内容
							likeTotal: 0,//回复点赞总数
							likeStatus: 0,//点赞状态，0：未点赞、1：点赞
							repliedUserName: type === 0 ? null : repliedUserName,//被回复者的用户名
							repliedUserID: beReplyID//被回复者的用户ID
						};
						commit(updateCommunityDetailDataCommentListReply, { params, data, isComFormAllReply });
						// 评论文章成功更新列表的评论数量 articleUserID:发布文章用户ID
						commit(UPDATE_LIST_VIEW_COMMENT_LIKE_ARTICLE, { ...params, isUpdateComment: true, articleUserID });
						uni.showToast({
							title: res && res.code === 200 ? '发布成功' : '发布失败，请重试',
							duration: 2000,
							icon: 'none'
						});
					}
				}
				return res;
			} catch (error) {
				console.error('INSERT_ARTICLE_COMMENT_REPLY', error);
				return error;
			}
		},
		// 删除文章评论回复
		async [DELETE_ARTICLE_COMMENT_REPLY] ({ commit }, params) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/reply/del', params);
				if (res && res.code === 200) {
				}
				const {
					articleUserID,
					commentID,
					replytID: replyID,
				} = params;
				commit(updateCommunityDetailDataCommentListReply, { params, commentID, replyID });
				// 评论文章成功更新列表的评论数量 articleUserID:发布文章用户ID
				commit(UPDATE_LIST_VIEW_COMMENT_LIKE_ARTICLE, { ...params, isUpdateComment: true, deleteComment: true, articleUserID });
				return res;
			} catch (error) {
				console.error('DELETE_ARTICLE_COMMENT_REPLY', error);
				return error;
			}
		},
		// 文章点赞 uniqueID文章ID
		async [UPDATE_LIKE_ARTICLE] ({ commit }, params) {
			try {
				const { isRecommend, isDynamic, isInformation, likeStatus, ...rest } = params;
				const url = likeStatus ? '/like/article' : '/like/del/article';
				const res = await uni.$http.post(prefixUrl() + url, rest);
				if (res && res.code === 200) { // 文章点赞成功更新列表的点赞数
				}
				// 点赞文章、评论、回复评论都需要更新文章的点赞数
				commit(UPDATE_LIST_VIEW_COMMENT_LIKE_ARTICLE, params);
				return res;
			} catch (error) {
				console.error('UPDATE_LIKE_ARTICLE', error);
				return error;
			}
		},
		// 评论点赞
		async [UPDATE_LIKE_COMMENT] ({ commit }, params) {
			try {
				const { likeStatus, ...rest } = params;
				const url = likeStatus ? '/like/comment' : '/like/del/comment';
				const res = await uni.$http.post(prefixUrl() + url, rest);
				if (res && res.code === 200) {
				}
				//
				// 在评论详情页点赞评论更新文章详情页的评论点赞数
				commit(upDateArticleDetailCommentListLike, params);
				// 点赞文章、评论、回复评论都需要更新文章的点赞数
				commit(UPDATE_LIST_VIEW_COMMENT_LIKE_ARTICLE, params);
				return res;
			} catch (error) {
				console.error('UPDATE_LIKE_COMMENT', error);
				return error;
			}
		},
		// 回复评论点赞
		async [UPDATE_LIKE_COMMENT_REPLY] ({ commit }, params) {
			try {
				const { likeStatus, ...rest } = params;
				const url = likeStatus ? '/like/reply' : '/like/del/reply';
				const res = await uni.$http.post(prefixUrl() + url, rest);
				// if (res) {
				// }
				// 点赞文章、评论、回复评论都需要更新文章的点赞数
				commit(UPDATE_LIST_VIEW_COMMENT_LIKE_ARTICLE, params);
				return res;
			} catch (error) {
				console.error('UPDATE_LIKE_COMMENT_REPLY', error);
				return error;
			}
		},
		// 举报文章
		async [REPORT_ARTICLE] ({ commit }, params) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/report/add', params);
				if (res) {
				}
				return res;
			} catch (error) {
				console.error('REPORT_ARTICLE', error);
				return error;
			}
		},
		// 删除文章
		async [DELETE_ARTICLE] ({ commit }, params) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/dynamic/del', params);
				if (res && res.code === 200) {
					commit(UPDATE_DELETE_ARTICLE, params);
					commit(UPDATE_USER_RELEASE_COUNT, { isAdd: false });
				}
				return res;
			} catch (error) {
				console.error('DELETE_ARTICLE', error);
				return error;
			}
		},
		// 获取个人动态页数据
		async [GET_USER_PERSON_LIST_INFORMATION] ({ commit }, params = {}) {
			const { isLoadMore, ...rest } = params;
			try {
				const url = isLoadMore ? '/person/getPersonTrendsList' : '/person/getPersonInformation';
				const res = await uni.$http.post(prefixUrl() + url, rest);
				if (res && res.code === 200) {
					const { data } = res;
					commit(setUserPersonListInformationData, { params, data, isLoadMore });
				}
				return res;
			} catch (error) {
				commit(setUserPersonListInformationData, { params, data: isLoadMore ? [] : { trendsContextList: [] }, isLoadMore });
				console.error('GET_USER_PERSON_LIST_INFORMATION', error);
				return error;
			}
		},
		// 发布个人动态
		async [INSERT_USER_PERSON_DYNAMIC] ({ commit }, params = {}) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/dynamic/add', params);
				if (params.status === 1 && res && res.code === 200 && res.data) {
					let { data } = res;
					data = {
						...data,
						picture: !data.pictures ? [] : data.pictures.map(item => ({
							picturePath: item.filePATH,
							pictureName: item.fileNM,
						})),
					};
					commit(INSERT_USER_PERSON_DYNAMIC, { data });
					commit(UPDATE_USER_RELEASE_COUNT, { isAdd: true });
          // uni.showToast({
          //   title: '发布成功',
          //   duration: 2000,
          //   icon: 'none'
          // });
				}
				return res;
			} catch (error) {
				console.error('INSERT_USER_PERSON_DYNAMIC', error);
				return error;
			}
		},
		// 获取发布动态草稿
		async [GET_USER_PERSON_DYNAMIC_DRAFT] ({ commit }, params = {}) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/dynamic/getSaveDynamic', params);
				if (res && res.code === 200) {
					const { data = {} } = res;
					commit(setUserPersonDynamicDraftData, { data });
				}
				return res;
			} catch (error) {
				console.error('GET_USER_PERSON_DYNAMIC_DRAFT', error);
				return error;
			}
		},
		// 获取文章详情分享小程序二维码
		async [GET_ARTICLE_SHARE_QRCODE] ({ commit }, params = {}) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/share/getCode', params);
				if (res && res.code === 200) {
					const { fileUrl } = res.data;
					commit(setArticleShareQrcode, { data: fileUrl });
				} else {
					commit(setArticleShareQrcode, { data: null });
				}
				return res;
			} catch (error) {
				commit(setArticleShareQrcode, { data: null });
				console.error('GET_ARTICLE_SHARE_QRCODE', error);
				return error;
			}
		},
		// 文章详情分享、保存海报后调用
		async [ARTICLE_SHARE_ADD] ({ commit }, params = {}) {
			try {
				const res = await uni.$http.post(prefixUrl() + '/share/add', params);
				return res;
			} catch (error) {
				console.error('ARTICLE_SHARE_ADD', error);
				return error;
			}
		},
	}
}
